package com.xpc.rpc.common.utils.yml;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class BootYamlUtils {


    private static final String YAM_FILE = "resources/application.yml";

    public static Object getProperties(String key) {
        YamlPropertiesFactoryBean yamlProFb = new YamlPropertiesFactoryBean();
        ClassPathResource classPathResource = new ClassPathResource(YAM_FILE);
        if(!classPathResource.exists()) {
            throw new RuntimeException("File not found");
        }
        yamlProFb.setResources(classPathResource);
        Properties properties = yamlProFb.getObject();
        Object result = properties.get(key);
        if(result == null) {
            throw new RuntimeException("properties key: " + key + " not exist");
        }
        return result;
    }

}
